package com.mofang.ticketing.order.serve.config;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author LGC
 */
@Configuration
public class ThreadPoolConfig {
    /**
     * 最大可用的CPU核数
     */
    public static final int PROCESSORS = Runtime.getRuntime().availableProcessors();

    @Bean
    public ThreadPoolExecutor getExecutor() {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(PROCESSORS, PROCESSORS * 2,
                5, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(), ThreadFactoryBuilder.create().setNamePrefix("order-task").build());
        return threadPoolExecutor;
    }
}